package com.ykt.mall.kit;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.ykt.model.Order;
import com.ykt.model.PaymentOrder;


public class BftPay {
	public static String payRequest(String merchantName, String phoneNo, Order order, String toUrl, String backUrl){
		Date dateNow = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
		String date = formatter.format(dateNow);
		String reqStr="";
		Double amount = order.getBigDecimal("all_money").doubleValue();
		Double postage = order.getBigDecimal("all_money").doubleValue();
		if (postage != null) {
			amount += postage;
		}
		/**
		 * 
		
		//发送"订单支付请求"数据包
		OrderPayRequest orderpay = new OrderPayRequest();//工具包"订单支付请求"类
		try {
			TransData sendData= new TransData();
			sendData.setMerID("560");
			sendData.setMerchantID("580000000000000");
			sendData.setMerName("测试商户");
			sendData.setPayID(order.getStr("id"));
			sendData.setOrderAmount(amount+"");
			sendData.setTransDate(date.substring(0, 8));
			sendData.setTransTime(date.substring(8));
			sendData.setMerHomeUrl(Content.SYS_URL+toUrl);
			sendData.setMerBackUrl(Content.SYS_URL+backUrl);

			String Description= java.net.URLEncoder.encode("测试订单2014","UTF-8");
			sendData.setDescription(Description);

			sendData.setTransType("2001");
			reqStr = orderpay.sendOrderPayRequest(sendData);

		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		 */
		return reqStr;
	}
	
	public static String payRequest(String merchantName, PaymentOrder paymentOrder, String toUrl, String backUrl){
		Date dateNow = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
		String date = formatter.format(dateNow);
		String reqStr="";
		Double amount = paymentOrder.getBigDecimal("amount").doubleValue();
		//发送"订单支付请求"数据包
		/**
		 * 
		OrderPayRequest orderpay = new OrderPayRequest();//工具包"订单支付请求"类
		
		
		TransData sendData= new TransData();
		sendData.setMerID("590");
		
		if(merchantName.equals("gls")){
			sendData.setMerchantID("590003060100009"); //固力士建材商行 正式账号：590003060100009
			sendData.setMerName("固力士建材商行");
		}else if(merchantName.equals("hyt")){//会员通订餐
			sendData.setMerchantID("590003060100002");//一卡通新（订餐）正式和测试账户   
			sendData.setMerName("一卡通新");
		}else if(merchantName.equals("yst")){//会员通订餐
			sendData.setMerchantID("590003060100013");//壹事通正式和测试账户   
			sendData.setMerName("e食通");
		}
		
		sendData.setPayID(String.valueOf(paymentOrder.getInt("id")));
		sendData.setOrderAmount(amount+"");
		sendData.setTransDate(date.substring(0, 8));
		sendData.setTransTime(date.substring(8));
		sendData.setMerHomeUrl(Content.SYS_URL+toUrl);
		sendData.setMerBackUrl(Content.SYS_URL+backUrl);//用户取消支付的地址
		
		if(paymentOrder.get("business_type").equals("1")){
			sendData.setDescription("微商城订单支付");
		}else if(paymentOrder.get("business_type").equals("2")){
			sendData.setDescription("预定订单支付");
		}else if(paymentOrder.get("business_type").equals("3")){
			sendData.setDescription("账单订单支付");
		}
		
		sendData.setTransType("2001");
		reqStr = orderpay.sendOrderPayRequest(sendData);
		*/
		return reqStr;
	}
	/**
	 *
	public static TransData decode(String encryptMsg){
		TransData transdata = new TransData();
		return transdata;
	}
	*/
	
}
